package logic

import (
	"context"
	"goods_srv/goods"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsAddLogic) GoodsAdd(req *types.CreateGoodsRequest) (resp *types.RegMsgResponse, err error) {
	// todo: 添加商品

	_, err = l.svcCtx.GoodsSrv.CreateGoods(l.ctx, &goods.CreateGoodsRequest{
		GoodsTitle:  req.GoodsTitle,
		GoodsPrice:  float32(req.GoodsPrice),
		GoodsStock:  int64(req.GoodsStock),
		GoodsStatus: int64(req.GoodsStatus),
		GoodsCover:  req.GoodsCover,
	})
	if err != nil {
		return &types.RegMsgResponse{
			Code: -1,
			Msg:  "添加失败",
			Data: nil,
		}, err
	}

	return &types.RegMsgResponse{
		Code: 0,
		Msg:  "添加成功",
		Data: nil,
	}, err
}
